<template>
  <el-table
    :data="tableData"
    show-summary :summary-method="getSummaries"
    style="width: 100%">
    <el-table-column
      prop="postName"
      label="岗位">
    </el-table-column>
    <el-table-column
      prop="male"
      label="男性数量/人">
      <template slot-scope="scope">
        <el-input type="number" v-model="scope.row.manNumber" size="small" clearable placeholder="请输入数量" :disabled="disabled"></el-input>
      </template>
    </el-table-column>
    <el-table-column
      prop="female"
      label="女性数量/人">
      <template slot-scope="scope">
        <el-input type="number" v-model="scope.row.womanNumber" size="small" clearable placeholder="请输入数量" :disabled="disabled"></el-input>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
  export default {
    props: {
      tableData: {
        type: Array,
        default: function () {
          return []
        }
      },
      disabled: {  // 是否可以编辑
        type: Boolean,
        default: false
      }
    },
    methods:{
      getSummaries(param){
        const { columns, data } = param;
        const sums = [];
        columns.forEach((column, index) => {
          if (index === 0) {
            sums[0] = '人数统计';
            return;
          }
          const values = data.map(item => Number(item[column.property]));
          if (index == 1){
            let sumNumber = 0;
            data.forEach(function(item, index) {
              sumNumber += Number(item.manNumber);
            })
            sums[1] = Number(sumNumber);
            return;
          }
          if (index == 2){
            let sumNumber = 0;
            data.forEach(function(item, index) {
              sumNumber += Number(item.womanNumber);
            })
            sums[2] = Number(sumNumber);
            return;
          }
          // if (column.property === 'male') {
          //
          //   sums[index] = values.reduce((prev, curr) => {
          //     const value = Number(curr);
          //     if (!isNaN(value)) {
          //       return prev + curr;
          //     } else {
          //       return prev;
          //     }
          //   }, 0);
          //   sums[index] += '';
          // }else{
          //   sums[index] = '--'
          // }
          //
          // if (column.property === 'female') {
          //   sums[index] = values.reduce((prev, curr) => {
          //     const value = Number(curr);
          //     if (!isNaN(value)) {
          //       return prev + curr;
          //     } else {
          //       return prev;
          //     }
          //   }, 0);
          //   sums[index] += ' ';
          // }
        });
        return sums;
      },
      // blurSearchFor(){
      //   console.log(this.placeholder)
      //   if(this.placeholder=='请输入数量'){
      //     this.placeholder = '';
      //   }
      // },
    }
  }
</script>
